package BusinessLogic;

import Data.LibraryInRecordOperator;

public class InventoryAnalysisModel implements IInventoryAnalysisModel{

	LibraryInRecordOperator liro = new LibraryInRecordOperator();
	
	public double[] getInformationByID(int ID){
		double d[] = new double[2];
		double ExpectedNumberOfDays = 0;
		double ExpectedScrapRite = 0;
		double daysCanStore = liro.getDaysCanStoreByID(ID);
		double totalCirculation = liro.getTotalCirculationByID(ID);
		double sizeDays = liro.getTodayToLastInLibraryDateByID(ID);
		double goodNum = liro.getNumOfInventoryByID(ID);
		double everydayCirculation = (Double)(totalCirculation/sizeDays);
		if(everydayCirculation > 0){
			ExpectedNumberOfDays = Math.max((goodNum/everydayCirculation),daysCanStore);
			
		}
		else{
			ExpectedNumberOfDays = 0;
			
		}
		
		if((ExpectedNumberOfDays != 0) && (goodNum/everydayCirculation < daysCanStore)){
			ExpectedScrapRite = 0;
		
		}
		else{if((ExpectedNumberOfDays != 0) && (goodNum/everydayCirculation > daysCanStore)){
			ExpectedScrapRite = (goodNum/everydayCirculation-daysCanStore)/(goodNum/everydayCirculation);
			
		}
		else{
			ExpectedScrapRite = 0;
			
		}

		}
		d[0] = ExpectedNumberOfDays;
		d[1] = ExpectedScrapRite;
			return d;
		
	}
	public double getExpectedScrapRiteByID(int ID){
		double d[] = getInformationByID(ID);
		return d[1];
	}
	
	public double getExpectedNumberOfDaysByID(int ID){
		double d[] = getInformationByID(ID);
		return d[0];
	}
	
}
